﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LuceneIndex;

namespace WebSearcher
{
    public partial class Admin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnStartIndex_Click(object sender, EventArgs e)
        {
            this.lblStatus.Text = "开始索引，请等候……";

            Thread indexThread = new Thread(new ThreadStart(StartIndex));
            indexThread.Start();
        }

        /// <summary>
        /// 多线程索引任务
        /// </summary>
        private void StartIndex()
        {
            DbFtpIndexer indexer = new DbFtpIndexer(
                ConfigurationManager.ConnectionStrings["connectionString"].ToString(),
                Server.MapPath("./index"));
            indexer.Index();

            this.lblStatus.Text = string.Format("索引完成，共索引{0}条记录，用时{1}秒", indexer.Count, indexer.ElapsedTime);
            Response.Redirect(Request.Url.ToString());
        }
    }
}
